package  
{
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.net.URLRequest;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.utils.Timer;
	import mx.core.BitmapAsset;
	import flash.text.Font;
	import com.greensock.*;
	/**
	 * ...
	 * @author KhanhNHV
	 */
	public class QuestionField extends MovieClip
	{
		[Embed(source = "../lib/wood-background.jpg")]
		private var Background:Class;
		[Embed(source = "../lib/din-light-webfont.ttf", fontName = "DinnLight")]
		private var FontDinnLight:Class;
		[Embed(source = "../lib/countdown_flip_0days.swf", mimeType = "application/octet-stream")]
		private var TimerCount:Class;
		public var textQuestion:TextField = new TextField();
		public var textCountDown:TextField = new TextField();
		public var timer:Timer;
		public var tickNumber : Number;
		public function QuestionField() 
		{
			var bmpAsset:BitmapAsset = new Background() as BitmapAsset;
			
			this.addChild(bmpAsset);			
			textQuestion.width = 1000;
			textQuestion.height = 756;
			textQuestion.x = 152;
			textQuestion.y = 136;
			
			Font.registerFont(FontDinnLight);
			var tf:TextFormat = new TextFormat("DinnLight", 50, 0xffffff);
			textQuestion.defaultTextFormat = tf;
			textQuestion.multiline = true;
			textQuestion.wordWrap = true;
			//textQuestion.embedFonts = true;
			textCountDown.defaultTextFormat = tf
			this.addChild(textQuestion);
			this.y = -1024
			this.alpha = 0;
			this.addEventListener(MouseEvent.CLICK, returnToNormal);
		}
		
		public function transitionIn()
		{
			timer = new Timer(1000, tickNumber);			
			timer.addEventListener(TimerEvent.TIMER_COMPLETE, timerComplete)
			timer.addEventListener(TimerEvent.TIMER, timerTick);
			timer.start();
			textCountDown.width = 100;
			textCountDown.height = 100;
			this.addChild(textCountDown);
			textCountDown.y = 200;
			textCountDown.x = 1200;
			TweenLite.to(this, 1.5, { y:0, alpha:1 } );
			
		}
		
		public function transitionOut()
		{
			timer.stop();
			timer.reset();
			TweenLite.to(this, 1.5, { y:-1024, alpha:0 } );
		}
		
		private function timerTick(evt:TimerEvent)
		{
			textCountDown.text = (tickNumber-timer.currentCount).toString();
		}
		
		private function timerComplete(evt:TimerEvent)
		{
			
		}
		
		private function  returnToNormal(me:MouseEvent):void 
		{
			parent.dispatchEvent(new CustomEvent(CustomEvent.RETURNTONORMAL, false, true, 0));
		}
		
		
	}

}